﻿using System;
using System.Threading.Tasks;
using Avalonia.Controls;
using Avalonia.Media.Imaging;
using Avalonia.Platform;
using CommunityToolkit.Mvvm.ComponentModel;

namespace AvaloniaLearning.ViewModels
{
    public partial class AppViewModel : ObservableObject
    {
        [ObservableProperty]
        private bool _isTrayIconVisible = true;

        [ObservableProperty]
        private WindowIcon? _trayIcon;

        private readonly WindowIcon _trayTransIcon = new(
            AssetLoader.Open(new Uri("avares://AvaloniaLearning/Assets/avalonia-logo.ico"))
        );

        public AppViewModel()
        {
            Task.Run(async () =>
            {
                while (true)
                {
                    TrayIcon = TrayIcon is null ? _trayTransIcon : null;
                    await Task.Delay(500);
                }
            });
        }
    }
}
